//
//  KWTMGRNSettingSelectCell.m
//  RuiHeApp
//
//  Created by Yan Chen on 2024/8/2.
//

#import "KWTMGRNSettingSelectCell.h"
@interface KWTMGRNSettingSelectCell()
@property (nonatomic, strong) QMUILabel *titleLab;

@property (nonatomic, strong) QMUITextField *textField;

@property (nonatomic, strong) QMUIButton *selectBtn;

@property (nonatomic, strong) UIImageView *arrowImg;
@end
@implementation KWTMGRNSettingSelectCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

-(void)setModel:(KWTMGRNSettingModel *)model
{
    _model = model;
    self.titleLab.text = [NSString stringWithFormat:@"%@:",model.rowTitle.rh_localized];
    self.textField.text = model.enumText.rh_localized;
    if (model.enumText.length == 0) {
        self.textField.text = @"--";
    }
    self.selectBtn.enabled = !model.readOnly;
    [self.arrowImg mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.offset(model.readOnly?0:18);
    }];
}

-(void)setupUI
{
    kWeakSelf;
    self.contentView.backgroundColor = kCOLOR_HEX(@"#F0F5FF");
    UIView *bgView = [[UIView alloc]init];
    bgView.backgroundColor = UIColor.whiteColor;
    [self.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 15, 0, 15));
    }];
    
    QMUILabel *titleLab = [QMUILabel labelWithText:@"" font:kSYSTEMFONT(14) textColor:kCOLOR_HEX_A(@"#171A1D",0.6)];
    titleLab.textAlignment = NSTextAlignmentLeft;
    [bgView addSubview:titleLab];
    self.titleLab = titleLab;
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(15);
        make.left.mas_offset(20);
        make.bottom.mas_offset(-15);
    }];
    
    UIImageView *arrow = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"arrow_2"]];
    self.arrowImg = arrow;
    [bgView addSubview:arrow];
    [arrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(18);
        make.right.mas_offset(-15);
        make.centerY.mas_offset(0);
    }];
    
    _textField = [[QMUITextField alloc]init];
    _textField.textAlignment = NSTextAlignmentRight;
    _textField.textColor = kCOLOR_HEX(@"#171A1D");
    _textField.text = @"卖电优先";
    _textField.textInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    _textField.userInteractionEnabled = NO;
    _textField.layer.cornerRadius = 5;
    _textField.layer.masksToBounds = YES;
    _textField.backgroundColor = kCOLOR_HEX(@"#ffffff");
    _textField.font = kSYSTEMFONT(14);
    _textField.placeholder = @"请选择".rh_localized;
    [bgView addSubview:_textField];
    [_textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLab.mas_right);
        make.height.offset(30);
        make.centerY.mas_offset(0);
        make.right.equalTo(arrow.mas_left).offset(0);
       
    }];
    
//    UIView *line = [[UIView alloc]init];
//    [bgView addSubview:line];
//    line.backgroundColor = kCOLOR_HEX_A(@"#7E868E",0.2);
//    [line mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_offset(15);
//        make.right.mas_offset(-15);
//        make.height.offset(1);
//        make.bottom.mas_offset(0);
//    }];
    
    QMUIButton *button = [[QMUIButton alloc]init];
    self.selectBtn = button;
    [bgView addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(bgView);
    }];
    
    [[button rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        if (weakSelf.selectAction) {
            weakSelf.selectAction(weakSelf.model);
        }
    }];
}

@end
